import { trans } from '@utils/common'
import { post, get, postL, getL } from '@utils/http'
import { SERVE_URL } from '@utils/config'

export default {
    apis: {
        //================参数===========
        LOG_LIST: SERVE_URL + 'apiExp/manager/sysLog/list',

        //=============定时任务===============
        SCHEDULE_LIST: SERVE_URL + 'apiExp/job/pageQuery',
        SCHEDULE_ADD: SERVE_URL + 'apiExp/job/add',
        SCHEDULE_EDIT: SERVE_URL + 'apiExp/job/edit',
        SCHEDULE_DELETE: SERVE_URL + 'apiExp/job/delete',
        SCHEDULE_EXECUTENOW: SERVE_URL + 'apiExp/job/executeNow',
        SCHEDULE_CHANGESTATUS: SERVE_URL + 'apiExp/job/changeStatus',
        SCHEDULE_GETINFO: SERVE_URL + 'apiExp/job/getInfo',

        //============监控================
        MONITORS: SERVE_URL + '/api{?}/sysMonitor/list',
    },

    async logs(pageNo, pageSize = 20, param) {
        const res = await trans(
            post(this.apis.LOG_LIST, {
                pageNo,
                pageSize,
                ...param,
            })
        );
        return res.data;
    },

    async schedules(pageNo, pageSize = 20, param) {
        const res = await trans(
            post(this.apis.SCHEDULE_LIST, {
                bo: { ...param },
                page: { currentPage: pageNo, pageSize: pageSize },
            })
        );
        return res.data;
    },

    async scheduleEdit(param) {
        const res = await trans(postL(this.apis.SCHEDULE_EDIT, param));
        return res.success;
    },
    async scheduleAdd(param) {
        const res = await trans(postL(this.apis.SCHEDULE_ADD, param));
        return res.success;
    },

    async scheduleDelete(jobId) {
        const res = await trans(getL(this.apis.SCHEDULE_DELETE, { jobId }));
        return res.success;
    },
    async scheduleExecuteNow(jobId) {
        const res = await trans(getL(this.apis.SCHEDULE_EXECUTENOW, { jobId }));
        return res.success;
    },
    async scheduleGetInfo(jobId) {
        const res = await trans(getL(this.apis.SCHEDULE_GETINFO, { jobId }));
        return res;
    },
    async scheduleChangeStatus(param) {
        const res = await trans(post(this.apis.SCHEDULE_CHANGESTATUS, param));
        return res.success;
    },

    async monitor(path) {
        const res = await trans(
            postL(this.apis.MONITORS, null, {
                pathParam: [path],
            })
        );
        return res.data;
    },
};
